<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script src="../vuejs/vue.js"></script>
    <template id="my-app">
        <div>{{info.name}}</div>
        <button @click="changeInfo()">改变info</button>
        <button @click="changeInfoName()">改变info的name</button>
    </template>
    <script>
        Vue.createApp({
            template: `#my-app`,
            data() {
                return {
                    info: {
                        name: 'zhang',
                        age: 18
                    }
                }
            },
            watch: {
                // 默认情况下我们的侦听器只会针对监听的数据本身的改变(内部发生的改变是不能侦听)
                // info(newValue, oldValue) {
                //     console.log('新值：',newValue,'旧值:',oldValue);

                // }
                //深度侦听
                info:{
                    handler:function(newValue,oldValue){
                     console.log('新值：',newValue,'旧值:',oldValue);

                    },
                    deep:true,//深度侦听
                    immediate:true//立即执行
                }
            },
            methods: {
                changeInfo() {
                    this.info = { name: 'li' };
                },
                changeInfoName(){
                    this.info.name='li';
                }
            }

        }).mount('#app')
    </script>
</body>

</html>